package com.yidu.BusinessParament.service.impl;

import com.yidu.BusinessParament.entity.Cash;
import com.yidu.BusinessParament.entity.Fund;
import com.yidu.BusinessParament.mapper.CashMapper;
import com.yidu.BusinessParament.service.CashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *现金账户实现层
 * @Version 1.0
 * @Author zsc
 * @Date 2022/12/8 14:37
 */
@Service
public class CashServiceImpl implements CashService {
    @Autowired
    private CashMapper cashMapper;

    /**
     * 查询现金账户表
     * @param page 当前页
     * @param limit 每页显示数
     * @param cash 现金账户对象
     * @return
     */
    public List<Cash> SelectCash(int page, int limit, Cash cash) {
        Map map=new HashMap ();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("strWhere",buildStrWhere(cash));
        return cashMapper.SelectCash (map);
    }

    /**
     * 生成条件字符串
     * @param cash 生成条件的参数
     * @return 条件字符串  and fundId like '%%'
     */
    public String buildStrWhere(Cash cash){
        StringBuffer strWhere=new StringBuffer("");
        if(cash.getAccountName ()!=null && !cash.getAccountName ().equals(""))
        {
            strWhere.append(" and accountName like '%"+cash.getAccountName ()+"%'");
        }
        if(cash.getBankName ()!=null && !cash.getBankName ().equals(""))
        {
            strWhere.append(" and bankName like '%"+cash.getBankName ()+"%'");
        }
        return  strWhere.toString();
    }

    /**
     * 分页查现金账户表行数 模糊查询后的行数
     * @param cash 现金账户对象
     * @return
     */
    public int SelectCashCount(Cash cash) {
        Map map=new HashMap();
        map.put("strWhere",buildStrWhere(cash));
        int count =cashMapper.SelectCashCount (map);
        return count;
    }

    @Override
    /**
     * 增加现金账户数据
     * @param cash 现金账户对象
     * @return
     */
    public int InsertCash(Cash cash) {
        return cashMapper.InsertCash(cash);
    }

    @Override
    /**
     * 查询最大ID的方法
     * @return
     */
    public String SelectMaxCashId() {
        return cashMapper.SelectMaxCashId ();
    }

    @Override
    /**
     * 删除现金账户数据
     * @param cashId 现金账户Id
     * @return
     */
    public int DeleteCash(String cashId) {
        //将id转为数据
        String[] split = cashId.split(",");
        //创建存放id的集合
        ArrayList<Object> list = new ArrayList<Object>();
        for (String id : split) {
            //将id存入集合
            list.add(id);
        }
        return cashMapper.DeleteCash (list);
    }

    @Override
    /**
     * 修改现金账户数据
     * @param cash 现金账户对象
     * @return
     */
    public int UpdateCash(Cash cash) {
        return cashMapper.UpdateCash (cash);
    }
}
